package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.cpu.PicInstructionFacade;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.Lengths;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 30, 2010
 * Time: 12:56:43 PM
 */
public final class ReturnWithLiteralInW implements PicInstruction {
    private final Bits argument;

    public ReturnWithLiteralInW(@NotNull final Bits argument) {
        if (argument.getLength() != Lengths.FILE_LENGTH) {
            throw new IllegalArgumentException(argument.toString());
        }
        this.argument = argument;
    }


    @NotNull
    @Override
    public List<? extends PicAction> getActions(@NotNull final PicInstructionFacade pic) {
        final List<PicAction> result = new ArrayList<PicAction>(2);
        result.add(pic.getActionFactory().popFromStackAction());
        result.add(pic.getActionFactory().createWriteInWAction(new RegisterValueImpl(argument)));
        return result;
    }
}
